package com.codeavatar.hardwaretester;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.codeavatar.catools.adapter.CaRecyclerViewAdapter;
import com.codeavatar.catools.base.CaBaseActivity;
import com.codeavatar.catools.helper.CaIntentHelper;
import com.codeavatar.catools.helper.CaToastHelper;

import com.codeavatar.hardwaretester.activity.hardware.BluetoothActivity;
import com.codeavatar.hardwaretester.activity.hardware.NfcActivity;
import com.codeavatar.hardwaretester.activity.hardware.WifiActivity;
import com.codeavatar.hardwaretester.data.MenuData;
import com.codeavatar.hardwaretester.databinding.ActivityMainBinding;
import com.codeavatar.hardwaretester.model.MenuModel;

import java.util.List;

public class MainActivity extends CaBaseActivity {

    private final String TAG = this.getClass().getSimpleName();

    //设置广播
    public static final String ACTION_APP_EXIT = "com.codeavatar.hardwaretester.action.exit";
    public static final String PERMISSION_APP_EXIT = "com.codeavatar.hardwaretester.app.location";

    private ActivityMainBinding mainBinding;
    List<MenuModel> listMenu;

    //++++++++++++++++++++++++++++++++++++++
    //++ 内部方法
    //++++++++++++++++++++++++++++++++++++++

    private void doLoad(){
        listMenu = MenuData.Init().getList();
        mainBinding.rvwList.setLayoutManager(new LinearLayoutManager(this));
        mainBinding.rvwList.setAdapter(this.listAdapter);
    }

    private RecyclerView.Adapter listAdapter = new CaRecyclerViewAdapter(){

        @Override
        public void bindView(RvViewHolder holder, int position) {
            MenuModel mm = listMenu.get(position);
            holder.setTextView(R.id.tvw_option,mm.getTitle());
        }

        @Override
        public void bindClick(View v, int position) {
            MenuModel mm = listMenu.get(position);
            if("bluetooth".equals(mm.getAction())){
                CaIntentHelper.init().startActivity(gActivity, BluetoothActivity.class);
            }else if("wifi".equals(mm.getAction())){
                CaIntentHelper.init().startActivity(gActivity, WifiActivity.class);
            }else if("nfc".equals(mm.getAction())){
                CaIntentHelper.init().startActivity(gActivity, NfcActivity.class);
            }else{
                CaToastHelper.toast(gActivity,String.format("未匹配到“%s”的操作",mm.getAction()));
            }
        }

        @Override
        public void bindChildClick(View v, int position) {

        }

        @Override
        public int getCount() {
            return listMenu.size();
        }

        @Override
        public int getResId() {
            return R.layout.layout_menu_list_item;
        }

        @Override
        public Context getContext() {
            return null;
        }

        @Override
        public boolean getClickable() {
            return true;
        }
    };

    //++++++++++++++++++++++++++++++++++++++
    //++ 重写方法
    //++++++++++++++++++++++++++++++++++++++

    @Override
    protected void initBinding() {
        mainBinding = ActivityMainBinding.inflate(getLayoutInflater());
    }

    @Override
    protected View getLayoutView() {
        return mainBinding.getRoot();
    }

    @Override
    protected void initNavigation() {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {
        this.doLoad();
    }

    @Override
    public void onClick(View v) {

    }
}